#include "logginginfo.h"
#include "ui_logginginfo.h"
#include "ClientSocket.h"
#include<QMessageBox>
#include "SocketException.h"
#include "vector_serialization.h"
#include<iostream>
#include<openssl/md5.h>
logginginfo::logginginfo(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::logginginfo)
{
        ui->setupUi(this);
        connect(ui->pushButton_submit, SIGNAL(clicked()),
                this, SLOT(handleSubmit()));
}

logginginfo::~logginginfo()
{
        delete ui;
}

void logginginfo::handleSubmit()
 {
        unsigned char md[16];
        char *a = "123456";
        std::string sendmsg, reply;
        std::string uname, upasswd, urole;
        uname = ui->lineEdit_uname->text().toStdString();
        upasswd = ui->lineEdit_upasswd->text().toStdString();
        urole = ui->comboBox_urole->currentText().toStdString();
        map<std::string, std::string> smap;
        smap["code"] = "003";
        smap["uname"] = uname;
        MD5((unsigned char *) a,strlen(a),md);
        //MD5((const unsigned char *) upasswd.c_str(), strlen(upasswd.c_str()), md);
        //upasswd = std::string((char *)md,16);
        std::cout << "md5:" << md << std::endl;
        cout << "upasswd:" << upasswd <<" " << upasswd.size() << endl;
        smap["upasswd"] = upasswd;
        if (!urole.compare("工作人员"))
                smap["urole"] = "w";
        else
                smap["urole"] = "m";
        sendmsg = save(smap);
        ClientSocket client_socket("localhost",30000);
        client_socket << sendmsg;
        client_socket >> reply;
        QString re = QString::fromStdString(reply);
        QMessageBox::about(0, "reply", re);
        this->close();
}
